package com.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class AspectByAno {

    @Pointcut("execution(* com.aop.*.*(..))")
    public void myPointCutByAno() {

    }

    @Before("myPointCutByAno()")
    public void myBefore(JoinPoint joinPoint) {
        System.out.println("****前置通知myBefore****切入的方法" +joinPoint.getTarget() );
        System.out.println("myBefore目标类====" + joinPoint.getSignature().getName());
    }

    @AfterReturning("myPointCutByAno()")
    public void myAfterReturning(JoinPoint joinPoint) {
        System.out.println("****后置返回通知myAfterReturning****切入的方法" +joinPoint.getTarget() );
        System.out.println("myAfterReturning目标类====" + joinPoint.getSignature().getName());
    }

    @Around("myPointCutByAno()")
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕开始******");
        Object obj = proceedingJoinPoint.proceed();
        System.out.println("环绕结束******");
        return obj;
    }

    @AfterThrowing(value = "myPointCutByAno()",throwing = "e")
    public void myException(JoinPoint joinPoint ,Throwable e) {
        System.out.println("异常通知***** 出错-->" + e.getMessage());
    }

    @After("myPointCutByAno()")
    public void myFinal() {
        System.out.println("最终通知==========");
    }
}
